<?php if ($this->_var['mix_list']): ?>
<script>
    $(function() {
        $("input:checkbox[name='goods_mix_id']").change(function() {
            var goods_mix_ids = get_goods_mix_id();
            var url = SITE_URL + '/index.php?app=cart&act=max_goods_cart';
            $.getJSON(url, {'goods_mix_ids': goods_mix_ids}, function(data) {
                if (data.done) {
                    $("#max_goods_total_price").html(price_format(data.retval.total_price));
                    $("#max_goods_total_count").html(data.retval.total_count);
                }
                else {
                    alert(data.msg);
                }
            });
        });
    });

    function add_goods_mix()
    {
        var store_id = <?php echo $this->_var['goods']['store_id']; ?>;
        var url = SITE_URL + '/index.php?app=cart&act=max_goods_add';
        var goods_mix_ids = get_goods_mix_id();
        $.getJSON(url, {'goods_mix_ids': goods_mix_ids}, function(data) {
            if (data.done) {
                location.assign(SITE_URL + '/index.php?app=order&goods=cart&store_id=' + store_id);
            }
            else {
                alert(data.msg);
            }
        });
    }

    /**
     * 获取点击事件
     */
    function get_goods_mix_id()
    {
        
        var goods_mix_ids = "";
        $("input:checkbox[name='goods_mix_id']:checked").each(function(i) {
            if (0 == i) {
                goods_mix_ids = $(this).val();
            } else {
                goods_mix_ids += ("," + $(this).val());
            }
        });
        return goods_mix_ids;
    }
</script>
<div class="goods_relation clearfix">
    <div class="mt">
        <h2>搭配购买</h2>
    </div>
    <div class="mc clearfix">
        <ul>
            <input type="checkbox"  name="goods_mix_id" value="<?php echo $this->_var['goods']['default_spec']; ?>" checked="checked" style="display:none">
            <?php $_from = $this->_var['mix_list']; if (!is_array($_from) && !is_object($_from)) { settype($_from, 'array'); }; $this->push_vars('', 'mix_item');$this->_foreach['fe_mix_item'] = array('total' => count($_from), 'iteration' => 0);
if ($this->_foreach['fe_mix_item']['total'] > 0):
    foreach ($_from AS $this->_var['mix_item']):
        $this->_foreach['fe_mix_item']['iteration']++;
?>
            <li id="mix_item_<?php echo $this->_var['mix_item']['cate_id']; ?>">
                <label>
                    <div class="p-img">
                        <img src="<?php echo $this->_var['site_url']; ?>/<?php echo $this->_var['mix_item']['default_image']; ?>">
                    </div>
                    <div class="p-name">
                        <?php echo htmlspecialchars($this->_var['mix_item']['goods_name']); ?>
                    </div>
                    <div class="p-price">
                        <input type="checkbox" name="goods_mix_id" value="<?php echo $this->_var['mix_item']['default_spec']; ?>" >
                        <strong><?php echo price_format($this->_var['mix_item']['price']); ?></strong>
                    </div>
                </label>
            </li>
            <?php endforeach; endif; unset($_from); ?><?php $this->pop_vars();; ?>
        </ul>
    </div>
    <div class="mb">
        <div class="p-name"></div>
        <div class="p-price">已选择：<strong id="max_goods_total_count">0</strong>个&nbsp;&nbsp;搭配价：<strong id="max_goods_total_price"><?php echo price_format($this->_var['goods']['price']); ?></strong></div>
        <div class="btns"><a href="javascript:add_goods_mix()">立即购买</a></div>
    </div>
</div>
<?php endif; ?>
